<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <link rel="stylesheet" href="/index/css/bootstrap.min.css" type="text/css">
	<link rel="stylesheet" href="/index/css/goods/public.css">
    <script src="/index/js/bootstrap.min.js"></script>
	<link href="/index/css/goods/balance.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="/index/js/goods/Calculation.js"></script>
    <script src="/index/js/address/leftnav.js"></script>
	<link rel="stylesheet" type="text/css" href="/index/css/leftnav.css">
	<title>我的购物车</title>
	<style type="text/css">
		body{background: #F5F5F5}
		#balance a {text-decoration: none;outline: none}
		.nav {background:#F8F8F8;height: 30px}
		.address {margin: 45px;background: white;}
		.addcart {background: white;margin: 45px;text-align: center;}
		.title {height: 30px;font-size: 18px;line-height: 30px;}
		.main {font-size: 14px;height: 60px}
		.number {padding: 0;margin: 0}
		.min,.add {width:25px; height:25px;border:1px solid #ccc;background: none}
		.text_box {width:30px; text-align:center; border:1px solid #ccc;height:25px;}
	</style>
</head>
<body>
	<div class="leftnav">
       <a href='/'><span>首页</span>返回首页</a>
       <a href='/index/user/info'><span><img src="/index/images/01.png"></span>个人中心</a>
       <a href='balance'><span><img src="/index/images/02.png"></span>购物车</a>
       <a href='/index/user/order'><span><img src="/index/images/03.png"></span>我的订单</a>
	</div>
	<div class="container-fluid">
		<div class="row nav">
			<div class="col-md-10">
			</div>
		</div>
		<div class="row address">
			<div class="col-md-12">
				<div class="row">
					<div class="col-md-1 col-md-offset-11 title" ><a href="/index/user/address">修改默认地址</a></div>
				</div>
			</div>
			<div class="col-md-12" style="text-align: center;height: 100px;line-height: 60px">
				<div class="row">
					<div class="col-md-2" ><img src="/index/images/portal-icon-2.png" height="70px" width="70px"></div>
					<div class="col-md-4" style="font-size: 20px ">{$address.0.city}&nbsp;&nbsp;{$address.0.address}</div>
					<div class="col-md-2" style="font-size: 20px ">{$address.0.name}</div>
					<div class="col-md-2" style="font-size: 20px ">&nbsp;&nbsp;{$address.0.phone}</div>
				</div>
			</div>
		</div>
		<div class="row addcart">
			<div class="col-md-12">
				<div class="row" style="margin-bottom: 30px;">
					<div class="col-md-2 title" ><!-- <b>全选</b> --></div>
					<div class="col-md-4 title" ><b>商品名称</b></div>
					<div class="col-md-2 title" ><b>数量</b></div>
					<div class="col-md-2 title" ><b>价格</b></div>
					<div class="col-md-2 title" ><b>操作</b></div>
				</div>
			</div>
			<div class="col-md-12">
				{volist name="cartinfo" id="result"}
				<div class="row" style="height: 80px;">
					<div class="col-md-2 main" ><img src="{$result.image}" width="50px" height="50px" /></div>
					<div class="col-md-4 main" >{$result.brand}{$result.category}{$result.color}{$result.memory}{$result.version}</div>
					<div class="col-md-2 main number">
						<input class="min" type="button" value="-" />  
						<input class="text_box" name="count" value="{$result.count}" id="{$result.id}" />
						<input class="add" type="button" value="+" /> 
					</div>
					<div class="col-md-2 main"><p class="price" id={$result.price}>{$result.price}</p></div>
					<div class="col-md-2 main del"><a href="del?id={$result.id}">删除</a></div>
				</div>
			{/volist}
			</div>
			<div class="col-md-12">
				<div class="row">
					<div class="col-md-2 title" >
						<!-- <input id="checkAll" class="allselect" type="checkbox" />全选 -->
					</div>
					<div class="col-md-4 title" ></div>
					<div class="col-md-2 title" >已选商品<span class="count"></span>件</div>
					<div class="col-md-2 title" ><p>总价：<label id="total"></label></p></div>
					<div class="col-md-2 title" ><button class="btn btn-info" id="balance"><a href="order">提交订单</a></button></div>
				<!-- </form> -->
				</div>
				<div class="row">
					<div class="col-md-12">&nbsp;</div>
				</div>
			</div>
		</div>
	</div>
</body>
<!-- 价格统计 -->
<script>  
    $(function() {  
        $(".add").click(function() {  
            var t = $(this).parent().find('input[class*=text_box]');  
            if(t.val()==""||undefined||null){  
                t.val(0);  
            }  
            t.val(parseInt(t.val()) + 1)  
            setTotal();  
        })  
        $(".min").click(function() {  
            var t = $(this).parent().find('input[class*=text_box]');  
            if(t.val()==""||undefined||null){  
                t.val(0);  
            }  
            t.val(parseInt(t.val()) - 1)  
            if(parseInt(t.val()) < 0) {  
                t.val(0);  
            }  
            setTotal();  
        })  
        $(".text_box").keyup(function(){  
            var t = $(this).parent().find('input[class*=text_box]');  
            if(parseInt(t.val())==""||undefined||null || isNaN(t.val())) {  
                t.val(0);  
            }  
            setTotal();  
        })  
        function setTotal() {  
            var s = 0;  
            $(".number").each(function() {  
                var t = $(this).find('input[class*=text_box]').val();
                var p = $('.price').html();
                // var p = $("#price").text();
                // alert()
                if(parseInt(t)==""||undefined||null || isNaN(t) || isNaN(parseInt(t))){  
                    t=0;  
                }  
                s += parseInt(t) * parseFloat(p);  
            });  
            $("#total").html(s.toFixed(2));
        } 
        setTotal();  
    })  
</script>
<script>
// 获取商品购买数量
	$("#balance").click(function(){
		$(".text_box").each(function(){
			var cartid = parseInt($(this).attr('id'));
			var count = parseInt($(this).val());
			$.post("update",{'cartid':cartid,'count':count},function(data){
				// window.location.href='order';
			});
		});
	});
</script>
<!-- 获取购买总数量 -->
<script type="text/javascript">
	// $(function(){
	// 	var count = parseInt($(this).val());
	// });
</script>
</html>